﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef ProgressBar_h__
#define ProgressBar_h__

#include "Scale9Image.h"
#include "Widget.h"
#include "../utility/SmartPtrDef.h"
#include "../base/Math.h"

namespace SkyEngine2d
{
	
	/*!
	 \brief 进度条控件
	*/
	class SGE_API ProgressBar
		:public Widget
	{
		UI_CLASS(ProgressBar)
	public:
		//! 创建一个进度条
		/*!
		\param const WidgetSharedPtr & parent 
		\return ProgressBarSharedPtr 
		*/
		static ProgressBar* create(Widget* parent =nullptr);
	
		//! 析构
		~ProgressBar();
	
		//! 设置进度条的 填充 图
		/*!
		\param std::unique_ptr<Scale9Image> image 填充图
		\return void 
		\sa void setBackgroundImage(std::unique_ptr<Scale9Image> image)
		*/
		void setFillImage(std::unique_ptr<Scale9Image> image);
		
		//! 设置进度条 填充区域 距离边界的距离
		/*!
		\param float top   上边距
		\param float left  左边距
		\param float bottom  下边距
		\param float right  右边距
		\return void 
		---------------------------------
		|								|
		|  ///////////////////////|	    |
		|								|   <- botton padding
		---------------------------------
		*/
		void setPadding(float top,float left,float bottom,float right);
	
		//! 设置进度条的最大值
		/*!
		\param int max_value 进度条的最大值
		\return void 
		*/
		void setMaxValue(int max_value);
	
		//! 设置进度条的最小值
		/*!
		\param int min_value 进度条的最小值
		\return void 
		*/
		void setMinValue(int min_value);
	
		//! 设置进度条的当前值
		/*!
		\param int value 进度条的当前值
		\return void 
		*/
		void setCurrentValue(int value);
	
		//! 获取进度条的最大值
		/*!
		\return int 
		\sa int getMinValue()const
		*/
		int getMaxValue()const;
	
		//! 获取进度条的最小值
		/*!
		\return int 
		\sa int getMaxValue()const
		*/
		int getMinValue()const;
	
		//! 获取当前的值
		/*!
		\return int 
		\sa 
		*/
		int getCurrentValue()const;
	
	protected:
		ProgressBar(Widget* parent = nullptr);
		virtual void draw(IRender* render, const Matrix4X4& transform);
	
		void updateFillRect();
	
	
		virtual bool init() override;
	
	
		virtual void onMoveEvent(EventWidgetMove * e) override;
	
	
		virtual void onResizeEvent(EventResize * e) override;
	
		void updateProgress();
	
	private:
	
		Scale9Image * m_currentBgImage;
	
		std::unique_ptr<Scale9Image> m_fillImag;
		std::unique_ptr<Scale9Image> m_bgImag;
	
		Rect  m_fillRect;  /*!< 填充的区域. */
		Rect  m_progressRect;  /*!< 当前进度的矩形. */
	
		float m_paddingTop;
		float m_paddingLeft;
		float m_paddingBotton;
		float m_paddingRight;
	
		int		m_maxValue;
		int		m_minValue;
		int		m_currentValue;
	
		Matrix4X4 m_mat;
	
	private:
		virtual void onWidgetStateChange() override;
		virtual void onWidgetStyleChange() override;
		void updataStyleInfo();
	};
	
}

#endif // ProgressBar_h__
